module.exports = (sequelize, DataTypes) => {
    return sequelize.define(
        'RepairPart',
        {
            id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                autoIncrement: true,
                primaryKey: true
            },
            repair_id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                references: {
                    model: 'Repair',
                    key: 'id'
                },
                validate: {
                    notNull: {
                        msg: '维修不能为空'
                    }
                }
            },
            part_id: {
                type: DataTypes.BIGINT.UNSIGNED,
                allowNull: false,
                references: {
                    model: 'Part',
                    key: 'id'
                },
                validate: {
                    notNull: {
                        msg: '配件不能为空'
                    }
                }
            },
            count: {
                type: DataTypes.INTEGER.UNSIGNED,
                allowNull: false,
                validate: {
                    notNull: {
                        msg: '数量不能为空'
                    },
                    min: {
                        args: 1,
                        msg: '使用数量不能小于1'
                    }
                }
            }
        },
        {
            tableName: 'repair_part'
        }
    )
}
